<?php 
//if uninstall not called from WordPress exit
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
	exit ();
	
	//remove all capabilities
	$mymail_options = get_option( 'mymail_options' );
	$roles = $mymail_options['roles'];
	
	global $wp_roles;
	
	foreach($roles as $role => $capabilities){
		foreach($capabilities as $capability){
			$wp_roles->remove_cap( $role, $capability);
		}
	
	}
	
	//remove all options
	global $wpdb;
	$wpdb->query("DELETE FROM `$wpdb->options` WHERE `$wpdb->options`.`option_name` LIKE 'mymail%'");
	$wpdb->query("DELETE FROM `$wpdb->options` WHERE `$wpdb->options`.`option_name` LIKE '_transient_mymail_%'");
	$wpdb->query("DELETE FROM `$wpdb->options` WHERE `$wpdb->options`.`option_name` LIKE '_transient_timeout_mymail_%'");
	$wpdb->query("DELETE FROM `$wpdb->options` WHERE `$wpdb->options`.`option_name` LIKE '_transient__mymail_%'");
	$wpdb->query("DELETE FROM `$wpdb->options` WHERE `$wpdb->options`.`option_name` LIKE '_transient_timeout__mymail_%'");
	//optimize DB
	$wpdb->query("OPTIMIZE TABLE `$wpdb->options`");
	
	//remove folder in the upload directory
	global $wp_filesystem;
	$upload_folder = wp_upload_dir();

	$wp_filesystem->delete($upload_folder['basedir'].'/myMail', true);

?>